//
//  DXstatuesOriginalView.swift
//  weiBoOfSwift
//
//  Created by simon on 15/12/10.
//  Copyright © 2015年 simon. All rights reserved.
//

import UIKit

 
class DXstatuesOriginalView: UIView {

    var statuesViewModel:DXStatuesViewModel?{
//        设置数据
        didSet{
    let statuesModel = statuesViewModel!.statuesMoel!
//            设置昵称
        nameLabel.text = statuesModel.user?.name
//            设置内容
//        textLaebl.text = statuesModel.text
//            retweetedTextLabel.attributedText = statuesViewModel!.retweetedStatuesAttribute
            textLaebl.statuesLinks = statuesViewModel!.originalStatuesLinks
            textLaebl.attributedText = statuesViewModel?.originalStatuesAttribute
//        logPrint(textLaebl.text)
        let imgUrl = NSURL(string: statuesModel.user!.profile_image_url!)
//            设置头像
        iconView.sd_setImageWithURL(imgUrl, placeholderImage: UIImage(named: "avatar_default_big"))
//            设置认证图标
        verifiedView.image = statuesViewModel?.verifiedIMG
            
//        logPrint(statuesModel.user?.verified)
//            设置会员图标
       mbrankView.image = statuesViewModel?.mbrankImg
//            设置来源文字
        soureLabel.text = statuesViewModel!.scoureText
//            设置时间文字
        created_time.text = statuesViewModel!.createdText
//            设置配图图片
        pictureView.pictures = statuesViewModel?.statuesMoel?.pic_urls
            
        }
    }
    
//    重写构造放啊
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.whiteColor()
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - 初始化UI
    private func setUpUI(){
//        添加子控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(mbrankView)
        addSubview(verifiedView)
        addSubview(created_time)
        addSubview(soureLabel)
        addSubview(textLaebl)
         addSubview(pictureView)
//       添加约束
//        头像
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(KStatuesCellMargin)
            make.leading.equalTo(self).offset(KStatuesCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
//        昵称
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView)
            make.leading.equalTo(iconView.snp_trailing).offset(KStatuesCellMargin)
        }
//        会员等级
        mbrankView.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(nameLabel)
            make.leading.equalTo(nameLabel.snp_trailing).offset(KStatuesCellMargin)
        }
//        微博认证
        verifiedView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_trailing)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        
        
//       发表时间
        created_time.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel)
            make.bottom.equalTo(iconView)
        }
//       微博来源
        soureLabel.snp_makeConstraints { (make) -> Void in
        make.leading.equalTo(created_time.snp_trailing).offset(KStatuesCellMargin)
            make.bottom.equalTo(created_time)
        }
//        微博内容
        textLaebl.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_bottom).offset(KStatuesCellMargin)
            make.leading.equalTo(iconView)
            make.trailing.equalTo(self).offset(-KStatuesCellMargin)
        }
        //        配图约束
    pictureView.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(textLaebl.snp_bottom).offset(KStatuesCellMargin)
        make.leading.equalTo(textLaebl)

    }

//        约束父控件的底部
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(pictureView.snp_bottom).offset(KStatuesCellMargin)
        }
        
//        iconView.cornerRadius = 35 * 0.5
    
    }
    // MARK: - 懒加载UI控件
//    头像
    lazy var iconView:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
//    昵称
    lazy var nameLabel:UILabel = UILabel(textColor: UIColor.darkTextColor(), fonSize: 15)
//    会员等级
    lazy var mbrankView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
//    微博认证
    lazy var verifiedView:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
//   发表时间
    lazy var created_time:UILabel = UILabel(textColor: UIColor.orangeColor(), fonSize: 10)
//   微博来源
    lazy var soureLabel:UILabel = UILabel(textColor:nil, fonSize: 10)
//    微博内容
    lazy var textLaebl:DXStatuesLabel = DXStatuesLabel(textColor: nil, fonSize: kstatuesFontSize)
//    配图
     lazy var pictureView:DXPictureView = DXPictureView()

}
